<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2017/9/10
 * Time: 6:56
 */
class mymodel{
    public static function getClassName($tableName){
        $prefix = r('prefix')?r('prefix'):'tbl_';

        //首字母处理
        $reg = "/^{$prefix}/i";
        $className = preg_replace( $reg,'',$tableName);
        $firstChar = strtoupper(substr($className,0,1));
        $className =  $firstChar.substr($className,1);

        //中间_处理
        $reg = "/_(\w)/i";
        $find = preg_match_all($reg,$className,$lowerMatches);
        if($find){
            for($c = 0; $c < count($lowerMatches[0]); $c++){
                $replaceReg = $lowerMatches[0][$c];
                $newChar = strtoupper($lowerMatches[1][$c]);
                $className =  str_ireplace($replaceReg,$newChar,$className);
            }
        }

        return $className;
    }


    public static function getClassFile($tableName){
        $lowerName = strtolower(self::getClassName($tableName));
        return ROOT_PATH."model/{$lowerName}.model.php";
    }

}

